<?php
namespace app\index\controller;
use think\Loader;
use think\Db;
/**
 * 菜单推送
 */
class Menu extends Base
{
	protected $model = '';
	public function init(){
		$this->model = Loader::model('manager/Menus');
	}
	public function pushMenu(){
		//开启事务
		Db::startTrans();
		try {
			$this->model->save(['status' => 0],['id' => ['NEQ', $this->request->get('id')]]);
		    $data = $this->model->where(['id' => $this->request->get('id')])->find();
			$data['status'] = 1;
			$data->save();
		    $menu = $this->app->menu;
			$menu->add(json_decode($data['content'],true)['button']);
			//提交事务
			Db::commit();
		} catch (\Exception $e) {
			//回滚事务
			Db::rollback();
		    throw $e;
		}
		return $this->redirect('/menu');
	}
}

?>